﻿using Md.Api.Model;
using Md.Api.Model.Manage.MdUser.Request;
using Md.Api.Service.Manage.MdUser;
using Microsoft.AspNetCore.Mvc;

namespace Md.Api.Controllers.Manage;
/// <summary>
/// 网站用户
/// </summary>
[ApiController]
[Produces("application/json")]
[Route("md-api/manage/md/user")]
public class MdUserController : ControllerBase
{
    /// <summary>
    /// 通过用户编号删除用户服务
    /// </summary>
    public DeleteMdUserByUserIdService deleteMdUserByUserIdService { get; set; }
    /// <summary>
    /// 通过用户编号删除用户
    /// </summary>
    /// <param name="userIds">用户编号多个逗号分割（1,2,3...）</param>
    /// <param name="signModel">加密实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpDelete("{userIds}")]
    public async Task<ResponseMessageModel> DeleteMdUserByUserId(string userIds, [FromQuery] RequestSignModel signModel)
    {
        var model = new RequestDeleteMdUserByUserIdModel();

        model.UserIds = userIds;
        model.TimesTamp = signModel.TimesTamp;
        model.Mac = signModel.Mac;
        model.Ip = signModel.Ip;
        model.Sign = signModel.Sign;
        model.Version = signModel.Version;
        model.Token = signModel.Token;

        return await Task.Run(() => deleteMdUserByUserIdService.Execute(model));
    }

    /// <summary>
    /// 添加用户服务
    /// </summary>
    public InsertMdUserService insertMdUserService { get; set; }
    /// <summary>
    /// 添加用户
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpPost]
    public async Task<ResponseMessageModel> InsertMdUser([FromBody] RequestInsertMdUserModel model)
    {
        return await Task.Run(() => insertMdUserService.Execute(model));
    }

    /// <summary>
    /// 通过用户编号更新用户服务
    /// </summary>
    public UpdateMdUserByUserIdService updateMdUserByUserIdService { get; set; }
    /// <summary>
    /// 通过用户编号更新用户
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpPut]
    public async Task<ResponseMessageModel> UpdateMdUserByUserId([FromBody] RequestUpdateMdUserByUserIdModel model)
    {
        return await Task.Run(() => updateMdUserByUserIdService.Execute(model));
    }

    /// <summary>
    /// 重置用户密码服务
    /// </summary>
    public ResetMdUserPwdByUserIdService resetMdUserPwdByUserIdService { get; set; }
    /// <summary>
    /// 重置用户密码
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("reset/pwd"), HttpPut]
    public async Task<ResponseMessageModel> ResetMdUserPwd([FromBody] RequestResetMdUserPwdByUserIdModel model)
    {
        return await Task.Run(() => resetMdUserPwdByUserIdService.Execute(model));
    }

    /// <summary>
    /// 通过用户编号获取用户信息服务
    /// </summary>
    public GetMdUserByUserIdService getMdUserByUserIdService { get; set; }
    /// <summary>
    /// 通过用户编号获取用户信息
    /// </summary>
    /// <param name="userId">用户编号</param>
    /// <param name="signModel">加密实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpGet("{userId}")]
    public async Task<ResponseMessageModel> GetSysUserByUserId(long userId, [FromQuery] RequestSignModel signModel)
    {
        var model = new RequestGetMdUserByUserIdModel();

        model.UserId = userId;
        model.TimesTamp = signModel.TimesTamp;
        model.Mac = signModel.Mac;
        model.Ip = signModel.Ip;
        model.Sign = signModel.Sign;
        model.Version = signModel.Version;
        model.Token = signModel.Token;

        return await Task.Run(() => getMdUserByUserIdService.Execute(model));
    }

    /// <summary>
    /// 获取用户列表服务
    /// </summary>
    public GetMdUserListService getMdUserListService { get; set; }
    /// <summary>
    /// 获取用户列表
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("list"), HttpPost]
    public async Task<ResponseMessageModel> GetSysUserList([FromBody] RequestGetMdUserListModel model)
    {
        return await Task.Run(() => getMdUserListService.Execute(model));
    }

    /// <summary>
    /// 分页获取用户列表服务
    /// </summary>
    public GetMdUserPageListService getMdUserPageListService { get; set; }
    /// <summary>
    /// 分页获取用户列表
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("listPage"), HttpPost]
    public async Task<ResponseMessageModel> GetSysUserPageList([FromBody] RequestGetMdUserPageListModel model)
    {
        return await Task.Run(() => getMdUserPageListService.Execute(model));
    }
}

